package cn.shiwei.pay.service.impl;

import cn.shiwei.basic.service.impl.BaseServiceImpl;
import cn.shiwei.basic.util.LoginContextUtil;
import cn.shiwei.pay.domain.PayBill;
import cn.shiwei.pay.mapper.PayBillMapper;
import cn.shiwei.pay.service.IPayBillService;
import cn.shiwei.user.domain.Logininfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;

@Service
public class PayBillServiceImpl extends BaseServiceImpl<PayBill> implements IPayBillService {

    @Autowired
    private PayBillMapper payBillMapper;

    @Override
    public void save(
            Long businessKey,
            String businessType,
            BigDecimal money,
            String title,
            Long payChannel,
            String unionPaySn,
            Long shopId,
            String shopName
            ) {
        PayBill payBill = new PayBill();
        Logininfo loininfo = LoginContextUtil.getLoininfo();

        payBill.setBusinessKey(businessKey);
        payBill.setBusinessType(businessType);
        payBill.setCreateTime(new Date());
        payBill.setPayChannel(payChannel);
        payBill.setDigest(title);
        payBill.setLogininfo_id(loininfo.getId());
        payBill.setMoney(money);
        payBill.setNickName(loininfo.getUsername());
        payBill.setState(PayBill.STATUS_PENDING_PAYMENT);
        payBill.setUnionPaySn(unionPaySn);

        payBill.setShopName(shopName);
        payBill.setShop_id(shopId);

        payBillMapper.save(payBill);

    }
}
